
function contentEditCtrl($http, $scope, $route, $rootScope, $timeout, commonService, $location) {
    _log('### contentEditCtrl ###');
    
    $scope.fieldData = { status: 1, catid: 1 };
    
    var param = $location.search();
    var url = 'content_ws.php';
    var contentid  = '';
    
    function loadData(){
        if(param['contentid']){
    	contentid = param['contentid'];
                var params = {
                   wsname : 'getcontentbyid',
                   id : contentid,
                   token : _pageData.tokenKey
                };
                $.getJSON(_COMMON.context + url, params).done(function(result) {
                    _COMMON.loading(null,'stop');
                	$scope.$apply(function() {
                	    $scope.fieldData = result.contents;
                	});
                });
                
                $("#title").prop("readonly",true);
        }
    }
    

   $scope.save = function() {
       
       	_COMMON.loading();
       	
	var data = $scope.fieldData;
	
	var config = {
	    params : {
		wsname : contentid == '' ? 'createcontent' : 'updatecontent',
		token : _pageData.tokenKey,
		id : contentid,
		alias : data.alias ? data.alias : '',
		title : data.title ? data.title : '',
		title_alias : data.title_alias ? data.title_alias : '',
		catid : data.catid,
		publishdate : $('#publishdate').val(),
		status : data.status,
		userid : _pageData.user.id ? _pageData.user.id : 'SYSTEM',
		introtext : data.introtext,
//		fulltext : $('textarea#fulltext').val()
		fulltext : encodeURI( $('textarea#fulltext').val())
	    }
//	    headers:{'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
	};
	
	jQuery.ajax({
	    type : "POST",
	    async : true,
	    url : _COMMON.context + url,
	    data : config['params'],
	    dataType : "json",
//	    contentType : "application/x-www-form-urlencoded; charset=UTF-8",
	    success : function(msg) {
		 notif({
	                msg: "<b><i class='fa fa-thumbs-o-up'></i>  Save Success !</b>",
	                type: "success",
	                position: "center"
	            });
    		location = '#/admin/content/list';
    	    }
	});

    };
    
  ///------------------------------------ Static Data -----
    $scope.categories = {};
    var url_2 = 'category_ws.php';
    var params_2 = {
        wsname: 'getallcategories',
        token: _pageData.tokenKey
    };
    $.getJSON(_COMMON.context + url_2, params_2).done(function (result) {
        $scope.$apply(function () {
            $scope.categories = result.categories;
        });
        loadData();
    });
    
    $(".datepicker").datepicker({
    	dateFormat : 'dd/mm/yy',
    	buttonImage : "app/images/calendar_blue.png",
    	beforeShow: function(){    
    	           $(".ui-datepicker").css('font-size', 13) ;
    	    }
    });
    
    

        	/*  ----------- CK Editor ---------*/
    var config = {
	height : _COMMON.winHeight - 189, // 189
	toolbarCanCollapse : true,
	resize_enabled : false,
	filebrowserBrowseUrl : 'app/lib/ckfinder/ckfinder.html',
	filebrowserImageBrowseUrl : 'app/lib/ckfinder/ckfinder.html?type=Images',
//	filebrowserFlashBrowseUrl : 'app/lib/ckfinder/ckfinder.html?type=Flash',
	filebrowserUploadUrl : 'app/lib/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
	filebrowserImageUploadUrl : '/app/lib/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
//	filebrowserFlashUploadUrl : 'app/lib/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'

    };
    $('#fulltext').ckeditor(config);
}
